//
//  ApiManagerHelper.swift
//  Wanke
//
//  Created by BO ZHOU on 2020/11/19.
//

import UIKit
import Alamofire


/**
 * 1. 负责日志打印
 */
extension BaseApiManager {
    
    
    class func apiEnd(withFullPath: String, method: HTTPMethod, headers: HTTPHeaders, parameters: [String: Any]?, dict: [String: Any], apiStartDate: Date?) {
        
        if apiNeedDebug {
            
            var api_time: Double = 0
            if apiNeedDebug {
                api_time = Date().timeIntervalSince(apiStartDate!)
            }
            
            if isPrintLog {
                
                if api_time == 0 {
                    print("================================================================================",
                          "url: \(withFullPath)\n",
                          
                          "method: \(method == .get ? "get" : "post")\n",
                          "header: \(headers)\n",
                          "param: \(String(describing: parameters))\n",
                          "responseData: \(dict)",
                          "================================================================================", separator: "\n")
                } else {
                    print("================================================================================",
                          "接口开始时间: \(apiStartDate!.dateString())",
                          "接口结束时间: \(Date().dateString())",
                          "接口耗时: \(api_time)\n",
                          "url: \(withFullPath)\n",
                          
                          "method: \(method == .get ? "get" : "post")\n",
                          "header: \(headers)\n",
                          "param: \(String(describing: parameters))\n",
                          "responseData: \(dict)",
                          "================================================================================", separator: "\n")
                }
            }
        }
    }
}
